package com.jisu.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jisu.common.ResultVo;
import com.jisu.pojo.Brand;
import com.jisu.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BrandController {
    @Autowired
    private BrandService brandService;

    /**
     * 查询所有品牌
     * @return 品牌列表
     */
    @GetMapping("/getAllBrands")
    public ResultVo<List<Brand>> getAllBrands() {
        try {
            // 查询所有品牌
            List<Brand> brands = brandService.list();
            return ResultVo.success("查询成功", brands);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.fail("查询失败");
        }
    }



    /**
     * 根据条件查询品牌（可选）
     * @param brandName 品牌名称（可选）
     * @return 品牌列表
     */
    @GetMapping("/searchBrands")
    public ResultVo<List<Brand>> searchBrands(String brandName) {
        try {
            QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
            if (brandName != null && !brandName.isEmpty()) {
                queryWrapper.like("brand_name", brandName);
            }
            List<Brand> brands = brandService.list(queryWrapper);
            return ResultVo.success("查询成功", brands);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.fail("查询失败");
        }
    }

}
